package com.gmall.item.service;

import com.gmall.common.result.Result;
import com.gmall.model.product.SkuInfo;
import com.gmall.model.product.dto.Category123IdNameDTO;
import com.gmall.product.feign.ProductApiFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@SuppressWarnings("all")
public class ItemService {

    @Autowired
    private ProductApiFeignClient productFeignClient;

    /*@Autowired
    private ListFeignClient listFeignClient;*/

    public Map<String, Object> getItem(Long skuId) {
        //创建对象，封装信息 多线程获取信息
        Map<String, Object> resultMap=new HashMap<>();

        Result<SkuInfo> skuInfo_result = productFeignClient.getSkuInfoById(skuId);
        if(skuInfo_result.isOk()){
            SkuInfo skuInfo = skuInfo_result.getData();
            resultMap.put("skuInfo",skuInfo);
            Result<Category123IdNameDTO> category123IdNameDTOResult = productFeignClient.getCategory123IdNameDTO(skuInfo.getCategory3Id());
            if(category123IdNameDTOResult.isOk()){
                Category123IdNameDTO category123IdNameDTO = category123IdNameDTOResult.getData();
                resultMap.put("categoryView",category123IdNameDTO);
            }
        }

        return resultMap;
    }
}
